import heapq
class Solution(object):
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        d = {}
        stack = []
        for i in range(len(s)):
            if s[i] in d:
                d[s[i]] = -1
            else:
                d[s[i]] = i
                heapq.heappush(stack, [i, s[i]])
        while stack:
            node = heapq.heappop(stack)
            if d[node[1]] >= 0:
                return node[0]
        return -1
